{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4a7d196e",
   "metadata": {},
   "source": [
    "# 人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "79f43142",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cb8f607f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679448,ce7d860f-b4a8-425a-8ce4-7c37d8106e5a', 'time_used': 212, 'faces': [{'face_token': '89c14d4a732dac696089f81571d74f70', 'face_rectangle': {'top': 207, 'left': 438, 'width': 172, 'height': 172}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 20}, 'smile': {'value': 0.005, 'threshold': 50.0}, 'emotion': {'anger': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.0, 'neutral': 99.99, 'sadness': 0.004, 'surprise': 0.005}, 'beauty': {'male_score': 81.522, 'female_score': 84.968}}}], 'image_id': '41dMPqOPHLHQE8GT5JEI5Q==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('day4.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'-5I_nvl7_hGNr9JZHdolud3YcGRpfMqV',\n",
    "    'api_secret':'cVl59_o8JqsSuBzKuyC9_BAO5bNeErnj',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,emotion,beauty'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd503765",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
